// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Analytics Hub API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_bigquery_analyticshub_v1::client::AnalyticsHubService;
/// let client = AnalyticsHubService::builder().build().await?;
/// // use `client` to make requests to the Analytics Hub API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// The `AnalyticsHubService` API facilitates data sharing within and across
/// organizations. It allows data providers to publish listings that reference
/// shared datasets. With Analytics Hub, users can discover and search for
/// listings that they have access to. Subscribers can view and subscribe to
/// listings. When you subscribe to a listing, Analytics Hub creates a linked
/// dataset in your project.
///
/// # Configuration
///
/// To configure `AnalyticsHubService` use the `with_*` methods in the type returned
/// by [builder()][AnalyticsHubService::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://analyticshub.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::analytics_hub_service::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::analytics_hub_service::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `AnalyticsHubService` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `AnalyticsHubService` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct AnalyticsHubService {
    inner: std::sync::Arc<dyn super::stub::dynamic::AnalyticsHubService>,
}

impl AnalyticsHubService {
    /// Returns a builder for [AnalyticsHubService].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_bigquery_analyticshub_v1::client::AnalyticsHubService;
    /// let client = AnalyticsHubService::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::analytics_hub_service::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::analytics_hub_service::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::AnalyticsHubService + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::AnalyticsHubService>>
    {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::AnalyticsHubService> {
        super::transport::AnalyticsHubService::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::AnalyticsHubService> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::AnalyticsHubService::new)
    }

    /// Lists all data exchanges in a given project and location.
    pub fn list_data_exchanges(&self) -> super::builder::analytics_hub_service::ListDataExchanges {
        super::builder::analytics_hub_service::ListDataExchanges::new(self.inner.clone())
    }

    /// Lists all data exchanges from projects in a given organization and
    /// location.
    pub fn list_org_data_exchanges(
        &self,
    ) -> super::builder::analytics_hub_service::ListOrgDataExchanges {
        super::builder::analytics_hub_service::ListOrgDataExchanges::new(self.inner.clone())
    }

    /// Gets the details of a data exchange.
    pub fn get_data_exchange(&self) -> super::builder::analytics_hub_service::GetDataExchange {
        super::builder::analytics_hub_service::GetDataExchange::new(self.inner.clone())
    }

    /// Creates a new data exchange.
    pub fn create_data_exchange(
        &self,
    ) -> super::builder::analytics_hub_service::CreateDataExchange {
        super::builder::analytics_hub_service::CreateDataExchange::new(self.inner.clone())
    }

    /// Updates an existing data exchange.
    pub fn update_data_exchange(
        &self,
    ) -> super::builder::analytics_hub_service::UpdateDataExchange {
        super::builder::analytics_hub_service::UpdateDataExchange::new(self.inner.clone())
    }

    /// Deletes an existing data exchange.
    pub fn delete_data_exchange(
        &self,
    ) -> super::builder::analytics_hub_service::DeleteDataExchange {
        super::builder::analytics_hub_service::DeleteDataExchange::new(self.inner.clone())
    }

    /// Lists all listings in a given project and location.
    pub fn list_listings(&self) -> super::builder::analytics_hub_service::ListListings {
        super::builder::analytics_hub_service::ListListings::new(self.inner.clone())
    }

    /// Gets the details of a listing.
    pub fn get_listing(&self) -> super::builder::analytics_hub_service::GetListing {
        super::builder::analytics_hub_service::GetListing::new(self.inner.clone())
    }

    /// Creates a new listing.
    pub fn create_listing(&self) -> super::builder::analytics_hub_service::CreateListing {
        super::builder::analytics_hub_service::CreateListing::new(self.inner.clone())
    }

    /// Updates an existing listing.
    pub fn update_listing(&self) -> super::builder::analytics_hub_service::UpdateListing {
        super::builder::analytics_hub_service::UpdateListing::new(self.inner.clone())
    }

    /// Deletes a listing.
    pub fn delete_listing(&self) -> super::builder::analytics_hub_service::DeleteListing {
        super::builder::analytics_hub_service::DeleteListing::new(self.inner.clone())
    }

    /// Subscribes to a listing.
    ///
    /// Currently, with Analytics Hub, you can create listings that
    /// reference only BigQuery datasets.
    /// Upon subscription to a listing for a BigQuery dataset, Analytics Hub
    /// creates a linked dataset in the subscriber's project.
    pub fn subscribe_listing(&self) -> super::builder::analytics_hub_service::SubscribeListing {
        super::builder::analytics_hub_service::SubscribeListing::new(self.inner.clone())
    }

    /// Creates a Subscription to a Data Clean Room. This is a
    /// long-running operation as it will create one or more linked datasets.
    /// Throws a Bad Request error if the Data Exchange does not contain any
    /// listings.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn subscribe_data_exchange(
        &self,
    ) -> super::builder::analytics_hub_service::SubscribeDataExchange {
        super::builder::analytics_hub_service::SubscribeDataExchange::new(self.inner.clone())
    }

    /// Refreshes a Subscription to a Data Exchange. A Data Exchange can become
    /// stale when a publisher adds or removes data. This is a long-running
    /// operation as it may create many linked datasets.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn refresh_subscription(
        &self,
    ) -> super::builder::analytics_hub_service::RefreshSubscription {
        super::builder::analytics_hub_service::RefreshSubscription::new(self.inner.clone())
    }

    /// Gets the details of a Subscription.
    pub fn get_subscription(&self) -> super::builder::analytics_hub_service::GetSubscription {
        super::builder::analytics_hub_service::GetSubscription::new(self.inner.clone())
    }

    /// Lists all subscriptions in a given project and location.
    pub fn list_subscriptions(&self) -> super::builder::analytics_hub_service::ListSubscriptions {
        super::builder::analytics_hub_service::ListSubscriptions::new(self.inner.clone())
    }

    /// Lists all subscriptions on a given Data Exchange or Listing.
    pub fn list_shared_resource_subscriptions(
        &self,
    ) -> super::builder::analytics_hub_service::ListSharedResourceSubscriptions {
        super::builder::analytics_hub_service::ListSharedResourceSubscriptions::new(
            self.inner.clone(),
        )
    }

    /// Revokes a given subscription.
    pub fn revoke_subscription(&self) -> super::builder::analytics_hub_service::RevokeSubscription {
        super::builder::analytics_hub_service::RevokeSubscription::new(self.inner.clone())
    }

    /// Deletes a subscription.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_subscription(&self) -> super::builder::analytics_hub_service::DeleteSubscription {
        super::builder::analytics_hub_service::DeleteSubscription::new(self.inner.clone())
    }

    /// Gets the IAM policy.
    pub fn get_iam_policy(&self) -> super::builder::analytics_hub_service::GetIamPolicy {
        super::builder::analytics_hub_service::GetIamPolicy::new(self.inner.clone())
    }

    /// Sets the IAM policy.
    pub fn set_iam_policy(&self) -> super::builder::analytics_hub_service::SetIamPolicy {
        super::builder::analytics_hub_service::SetIamPolicy::new(self.inner.clone())
    }

    /// Returns the permissions that a caller has.
    pub fn test_iam_permissions(
        &self,
    ) -> super::builder::analytics_hub_service::TestIamPermissions {
        super::builder::analytics_hub_service::TestIamPermissions::new(self.inner.clone())
    }

    /// Creates a new QueryTemplate
    pub fn create_query_template(
        &self,
    ) -> super::builder::analytics_hub_service::CreateQueryTemplate {
        super::builder::analytics_hub_service::CreateQueryTemplate::new(self.inner.clone())
    }

    /// Gets a QueryTemplate
    pub fn get_query_template(&self) -> super::builder::analytics_hub_service::GetQueryTemplate {
        super::builder::analytics_hub_service::GetQueryTemplate::new(self.inner.clone())
    }

    /// Lists all QueryTemplates in a given project and location.
    pub fn list_query_templates(
        &self,
    ) -> super::builder::analytics_hub_service::ListQueryTemplates {
        super::builder::analytics_hub_service::ListQueryTemplates::new(self.inner.clone())
    }

    /// Updates an existing QueryTemplate
    pub fn update_query_template(
        &self,
    ) -> super::builder::analytics_hub_service::UpdateQueryTemplate {
        super::builder::analytics_hub_service::UpdateQueryTemplate::new(self.inner.clone())
    }

    /// Deletes a query template.
    pub fn delete_query_template(
        &self,
    ) -> super::builder::analytics_hub_service::DeleteQueryTemplate {
        super::builder::analytics_hub_service::DeleteQueryTemplate::new(self.inner.clone())
    }

    /// Submits a query template for approval.
    pub fn submit_query_template(
        &self,
    ) -> super::builder::analytics_hub_service::SubmitQueryTemplate {
        super::builder::analytics_hub_service::SubmitQueryTemplate::new(self.inner.clone())
    }

    /// Approves a query template.
    pub fn approve_query_template(
        &self,
    ) -> super::builder::analytics_hub_service::ApproveQueryTemplate {
        super::builder::analytics_hub_service::ApproveQueryTemplate::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::analytics_hub_service::GetOperation {
        super::builder::analytics_hub_service::GetOperation::new(self.inner.clone())
    }
}
